﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AccordMaker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Panel panel = new Panel();
            panel.Size = new Size(600, 150);
            panel.BackColor = Color.White;
            panel.Name = "AccPanel";
            panel.Location = new Point(button1.Location.X, button1.Location.Y + 50);
            Controls.Add(panel); 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            
           // Panel p1 = Controls.Find("AccPanel",false).First() as Panel;
            MyLabel m = new MyLabel();
            m.Location = new Point(200,200);//new Point(p1.Location.X + 10, p1.Location.Y + 10);
            m.Text = "test";
            m.MouseDown += new MouseEventHandler(MyControl_MouseDown);
            m.MouseMove += new MouseEventHandler(MyControl_MouseMove);
            Controls.Add(m);
           
            
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private Point MouseDownLocation;
        private Control currentControl;

        private void MyControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                currentControl = (Control)sender;
                MouseDownLocation = e.Location;
            }
        }

        private void MyControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                currentControl.Left = e.X + currentControl.Left - MouseDownLocation.X;
               // this.Top = e.Y + this.Top - MouseDownLocation.Y;
            }
        }
    }
    class MyLabel : Label
    {
    }
}
